<?php

function restaurant_day_render($day,$colored_days){
    if (isset($colored_days[$day]))
      return $day; // színezendő
    else
      return $day;
}

function restaurant_calendar_block_content(){
    
    $colored_days = array();
    
    
    
    return drupal_render(drupal_get_form('restaurant_calendar_form')).restaurant_calendar_table($colored_days);
    
}

function restaurant_calendar_form($form,$form_state){
        $restaurants=restaurant_get_restaurants_names();
        $form['restaurant'] = array(
        '#type' => 'select',
        '#title' => t('Éttermek listája:'),
        '#options'=> $restaurants,
        );  
        return $form;
}

function restaurant_calendar_table($colored_days=''){
    $date=time();
    
    $day=date('d',$date);
    $month=date('m',$date);
    $year=date('y',$date);
    
    $first_day=  mktime(0,0,0,$month,1,$year);
    
    $title =date('F',$first_day);
    
    $day_of_week =date('D',$first_day);
    
    switch ($day_of_week){
        case "Mon": $blank=0; break;
        case "Tue": $blank=1; break;
        case "Wed": $blank=2; break;
        case "Thu": $blank=3; break;
        case "Fri": $blank=4; break;
        case "Wed": $blank=5; break;
        case "Sun": $blank=6; break;   
    }
    
    $days_in_month= cal_days_in_month(0, $month, $year);
    

    $day_count=1;

    $row_counter=0;
    $rows=array();
    $rows[$row_counter]=array();
    while($blank > 0)
    {
        $rows[$row_counter][]="";
        $blank=$blank-1;
        $day_count++;
    }
    $day_num=1;
    
    while($day_num<= $days_in_month){
        $rows[$row_counter][]=restaurant_day_render($day_num,$colored_days);
        $day_num++;
        $day_count++;
        if ($day_count>7){
            $row_counter++;
            $rows[$row_counter] = array();
            $day_count=1;
        }
    }

    while($day_count>1 && $day_count <=7){
        $rows[$row_counter][]='';
        $day_count++;
    }

    $header= array(
        'H','K','S','C','P','S','V'
    );

    
    $html = theme('table', 
        array(
            'header' => $header,
            'rows'=>$rows,
            'sticky' => TRUE,		
            )
    );
    
    return $html;
}